package cn.HuanG.org.controller;

import cn.HuanG.org.domain.OtherLogEntity;
import cn.HuanG.org.query.OtherLogQuery;
import cn.HuanG.org.service.IOtherLogService;
import cn.HuanG.util.AjaxResult;
import cn.HuanG.util.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/log")
@Api(tags = "日志接口",description = "日志接口详细描述")
public class OtherLogController {
    @Autowired
    private IOtherLogService otherLogService;

    //查询全部
    @GetMapping //@RequestMapping(method = {RequestMethod.GET})
    public List<OtherLogEntity> getAll(){
        return otherLogService.queryAll();
    }
    @PutMapping//新增或修改
    public AjaxResult saveOrUpdate(@RequestBody OtherLogEntity OtherLogEntity){// @RequestBody接收json数据
        try {
            if (OtherLogEntity.getId()==null){
                // 新增
                otherLogService.save(OtherLogEntity);
            }else {
                // 修改
                otherLogService.update(OtherLogEntity);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }
    @DeleteMapping("{id}")//删除
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            otherLogService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }
    @GetMapping("{id}")// 根据id查询
    public OtherLogEntity findById(@PathVariable("id") long id){
        return otherLogService.queryById(id);
    }

    @PostMapping// 分页
    public PageInfo<OtherLogEntity> page(@RequestBody OtherLogQuery query){//接收json数据
        return otherLogService.queryPage(query);
    }

    @PatchMapping // 批量删除
    public AjaxResult patchDelete(@RequestBody Long[] ids){
        try {
            otherLogService.patchDelete(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }
}
